<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>获取数据</button>
    <ul></ul>

    <script>
        let button = document.querySelector('button');
        let ul = document.querySelector('ul');

        button.onclick = function() {
            let xhr = new XMLHttpRequest();

            xhr.open('get', '/', true);

            xhr.onload = function() {
                let data = JSON.parse(this.responseText);
                data.forEach(d => {
                    let li = document.createElement('li');
                    li.innerHTML = d.name;
                    ul.appendChild(li);
                })
            }

            xhr.send();
        }
    </script>
</body>
</html>